﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sector7.Framework.Core
{
    /// <summary>
    /// ExcelSheet
    /// </summary>
    public class ExcelSheet
    {
        #region Inner members

        /// <summary>
        /// Sheet Name
        /// </summary>
        private string m_sheetName;

        /// <summary>
        /// Row Count
        /// </summary>
        private int m_rowCount;

        /// <summary>
        /// Column Count
        /// </summary>
        private int m_columnCount;

        /// <summary>
        /// Cell Values
        /// </summary>
        private Dictionary<Tuple<int, int>, object> m_cellValues = new Dictionary<Tuple<int, int>, object>();

        #endregion

        #region Accessor
        #endregion

        #region Structure

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="sheetName">Sheet Name</param>
        /// <param name="rowCount">Row Count</param>
        /// <param name="columnCount">Column Count</param>
        public ExcelSheet(string sheetName, int rowCount, int columnCount)
        {
            m_sheetName = sheetName;
            m_rowCount = rowCount;
            m_columnCount = columnCount;
        }

        #endregion

        #region Public functions

        /// <summary>
        /// 添加单元格值
        /// </summary>
        /// <param name="row">行号</param>
        /// <param name="column">列号</param>
        /// <param name="value">单元格值</param>
        public void AddValue(int row, int column, object value)
        {
            Tuple<int, int> tuple = new Tuple<int, int>(row, column);

            try
            {
                m_cellValues.Add(tuple, value);
            }
            catch (Exception ex)
            {
                Log.WriteLine(Enums.LogSeverityType.ERR, "ExcelSheet", "AddValue: insert key value pair into m_cellValues failed.");
                Log.WriteLine(Enums.LogSeverityType.ERR, "ExcelSheet", "AddValue: {0}", ex);
            }
        }

        /// <summary>
        /// Get Value
        /// </summary>
        /// <param name="row">行号</param>
        /// <param name="column">列号</param>
        /// <returns></returns>
        public object GetValue(int row, int column)
        {
            Tuple<int, int> tuple = new Tuple<int, int>(row, column);
            object value = null;
            bool result = m_cellValues.TryGetValue(tuple, out value);
            if (result)
            {
                return value;
            }
            else
            {
                Log.WriteLine(Enums.LogSeverityType.ERR, "ExcelSheet", "GetValue: can NOT get value at [{0}, {1}].", row, column);
                return null;
            }
        }

        #endregion

        #region Private functions
        #endregion
    }
}
